#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <signal.h> 
#include <stdlib.h>       
#include <string.h>
#include <pthread.h>
//#include <sys/sem.h>
#include <errno.h>
#include <sys/ipc.h>
//#include <sys/msg.h>
#include <sys/timeb.h>
#include <sys/socket.h>
//#include <sys/socketvar.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <semaphore.h>
#include <string.h>
#include <termios.h>
#include <linux/input.h>
#include <semaphore.h>
#include <linux/shm.h>
#include <asm/unistd.h>
#include <sys/poll.h>

#include "common.h"


static bool initFinish = false;

static int screenWidth  = 0;
static int screenHeight = 0;

int initCompose()
{
		initFinish = true;
		
		return 0;
}

void composeCap(struct recvData *recvData)
{
		if(initFinish == false)
		{
				printf("initFinish == false ! {%s,%d}\n", __FILE__, __LINE__);
				return;
		}
		
		unsigned char *pRevData = recvData->buf;
		unsigned int recvPackageSize = recvData->count;
		unsigned char *pRevVideoData = pRevData + 17;
		unsigned int h264DataSize = recvPackageSize - 17;
		
		if(pRevData[0] != 0xF1)
		{
				printf("composeCap:pRevData[0] != 0xF1 ! pRevData[0]=%d {%s,%d}\n", pRevData[0], __FILE__, __LINE__);
				return;	
		}
	
		screenWidth  = ((0x00FF&recvData->buf[1])<<8)|(0x00FF&recvData->buf[2]);	
		screenHeight = ((0x00FF&recvData->buf[3])<<8)|(0x00FF&recvData->buf[4]);	
		
		//int total = ((0x00FF&recvData->buf[12])<<8)|(0x00FF&recvData->buf[13]);	
		//int	index = ((0x00FF&recvData->buf[14])<<8)|(0x00FF&recvData->buf[15]);	
		int size  = recvData->count - 17;
		
		printf("get compose size = %d\n", size);
		
		sendOneMicroClassVideoData(pRevData, recvPackageSize);
}

void GetComposeWidthHeight(int *w,int *h)
{
		*w = screenWidth;
		*h = screenHeight;	
}
